package com.yanqu.road.server.cmd.player;

import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code= Protocol.S_SYSTEM_PREVIEW_REWARD, desc = "领取系统预告奖励")
public class GetSystemPreviewRewardCmd extends AbstractCommand {
    private int systemId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PlayerProto.SystemOpenPreviewRewardReqMsg reqMsg = PlayerProto.SystemOpenPreviewRewardReqMsg.parseFrom(packet.getBytes());
        systemId = reqMsg.getSystemId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(PlayerModule.class).getSystemPreviewReward(systemId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0) {
            PlayerProto.SystemOpenPreviewRewardRespMsg.Builder respMsg = PlayerProto.SystemOpenPreviewRewardRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_SYSTEM_PREVIEW_REWARD, respMsg);
        }
    }
}
